home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
39
< prev
next >
Wrap
Text File
|
1996-08-06
|
2KB
|
61 lines
Path: qcd.lanl.gov!tanmoy
From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
Newsgroups: comp.std.c
Subject: Re: Undefined result vs. int's holding undefined values.
Date: 6 Jan 1996 00:11:48 GMT
Organization: Los Alamos National Laboratory
Distribution: world
Message-ID: <4ckeo4$sf5@newshost.lanl.gov>
References: <4ck70b$rd7@news.informix.com>
NNTP-Posting-Host: qcd.lanl.gov
In article <4ck70b$rd7@news.informix.com>, Daniel Wood <dwood> writes:
|> THE TEST CASE, on SCO:
|>
|> main() { f(-2147483647, 1879048192); }
|>
|> f(int x, int y) {
|> int r;
|>
|> if ((r=(x-y)) > 0)
|> printf("1: r greater than 0\n");
|>
|> if (r > 0)
|> printf("2: r greater than 0\n");
|> }
|>
|> On SCO only the second print occurs. The reason given to me is that ANSI
|> states
|> that the result of an overflowing/underflowing operation is undefined. The
|> implementation is free to do what it wants with the result. This is fine
<snip>
|> Saying a result is undefined "IS NOT EQUAL TO" saying that a C int
variable
|> can actually hold an undefined value. If you think the test case is
running
|> acceptably, as described above, then tell me the section of the standard
that
|> states or implies that an int variable can hold an undefined value.
|>
|> Why say ye all?
3.14 defines `undefined behaviour' as `behaviour, upon use of nonportable or
erroneous program construct, of errnoeous data, or of indeterminately valued
objects, for which this International Standard imposes no requirements.' Note
that the entire _behaviour_ is undefined if erroneous data or an
indeterminately valued object is used. So, a compiler is within rights to do
whatever it sees fit, because it is not bound by any `requirements' of the
standard including, inter alia, the requirement that the value of a variable
not change arbitrarily; or that the controlled statement in an if be executed
if the control expressions evaluates unequal to 0.
Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]